<style>
    .welcome_set {
        margin-top: 25px;
    }
    
    .head {
        display: flex;
        justify-content: space-between;
        height: 38px;
        line-height: 38px;
    }
</style>
<div class="welcome_set layui-container layuimini-container">
    <div class="layuimini-main">
        <div class="head">
            <h3><strong>系统公告设置</strong></h3>
        </div>
        <!-- 分割线 -->
        <div>
            <hr class="layui-border-black">
        </div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">公告标题:</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入公告标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">公告内容:</label>
                <div class="layui-input-block">
                    <textarea name="content" lay-verify="content" placeholder="请输入公告内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">发布</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function(value) {
                if (value.length < 1) {
                    return '标题至少得5个字符啊';
                }
            }

        });

        //监听提交
        form.on('submit(demo1)', function(data) {
            var contentText=data.field.content.replace(/\r\n/g,"<br>")
            contentText=contentText.replace(/\n/g,"<br>");
            jq1111.ajax({
                type: "POST",
                crossDomain: true,
                url: BasePath+"api/Notification/AddNotice",
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify({
                    "title": data.field.title,
                    "content": contentText,
                    "isAlert": false,
                }),
                xhrFields: {
                    withCredentials: true
                },
                success: function(message) {
                    console.log(message)
                    location.reload()
                    layer.msg(message.msg);
                },
                error: function(message) {
                    console.log(message.responseJSON);
                    layer.msg('失败:' + message.responseJSON.msg);
                },
            });

            return false;
        });
    });
</script>